package com.dc.docs._888_面试.concurrent._2_cas;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.concurrent.atomic.AtomicReference;

/**
 * Description: 原子更新引用
 * @author: gdc
 * @date: 2021/6/15
 * @version 1.0
 */
public class Cas_3_AtomicReference {

    public static void main(String[] args){
        AtomicReference<User> atomicReference = new AtomicReference<>();

        User user = new User("monster", 18);
        User updateUser = new User("jack", 25);

        atomicReference.set(user);
        atomicReference.compareAndSet(user, updateUser);

        System.out.println(atomicReference.get());
    }
}


@Data
@AllArgsConstructor
class User{
    private String name;
    private Integer age;
}
